<template>
  <div class="page">
    <div class="width-style">
      <div class="user">
        <div style="display: flex">
<!--          第一版-->
          <!--头像-->
          <div>
            <el-avatar shape="circle" :size="100"
                       :src="avatar">
            </el-avatar>
          </div>
          <!--用户名-->
          <div class="user_info">
            <div class="user_info_wrap">
							<span>用户名：{{userInfo.nickName}}
								<el-tag size="mini" style="font-size: 14px; color: #25b6a0; cursor: pointer" v-for="(item,index) in userInfo.roles" :key='index' @click="toDoctorShow(userInfo.userId)">{{item.roleName}}</el-tag>
							</span>
            </div>
            <div class="user_notinfo_wrap">
              <span>{{like}}被点赞</span>
              <el-divider direction="vertical"></el-divider>
              <span>{{pub}}浏览</span>
              <el-divider direction="vertical"></el-divider>
              <span>{{fans}}粉丝</span>
            </div>
            <div class="intro">
              <span>目前就职：{{userInfo.career?userInfo.career:'暂无'}}</span>
            </div>
            <div class="intro">
              <span>简介：{{userInfo.description?userInfo.description:'暂无'}}</span>
            </div>
          </div>
        </div>
        <!--关注按钮-->
        <div class="guanzhu">
          <button @click="favor" class="my_button" :style="{ backgroundColor: bg_color, color: ft_color }"
                  @mouseenter="change()" @mouseleave="goback()">
            {{content}}
          </button>

        </div>
      </div>
      <el-row type="flex" justify="space-between">
        <!--个人成就以及标签栏-->
        <el-col :span="5">
          <div class="left_show_wrap">
            <span>个人成就</span>
            <el-divider></el-divider>
            <div style="font-size: 18px;">
              暂无
            </div>
            <!--						<div class="left_achi_wrap">-->
            <!--							<div>-->
            <!--								&lt;!&ndash; 点赞图标&ndash;&gt;-->
            <!--								<i class="el-icon-thumb"></i>-->
            <!--								<span>获得65次点赞</span>-->
            <!--							</div>-->
            <!--							<div>-->
            <!--								<i class="iconfont icon-shoucang cjsc"></i>-->
            <!--								<span>获得113次收藏</span>-->
            <!--							</div>-->
            <!--							<div>-->
            <!--								<i class="iconfont icon-pinglun cjpl"></i>-->
            <!--								<span>内容获得65次评论</span>-->
            <!--							</div>-->
            <!--						</div>-->
          </div>
        </el-col>
        <!-- Ta的发布-->
        <el-col :span="18">
          <div>
            <div class="breadcrumb_wrap">
              <span>Ta的发布({{pubTotal}})</span>
            </div>
            <div class="page_card" v-if="!pubTotal">
              暂无
            </div>
            <div class="page_card" v-if="pubTotal">
              <articleShow :articleList='articleList'/>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
// import articleShow from "@/components/articleShow.vue";
import articleShow from "@/components/pubList.vue";
export default {
  layout: "personalCenterLayout",
  name: "PersonalShow",
  components:{
    articleShow
  },
  data() {
    return {
      like:null,
      pub:null,
      fans:null,
      liked: false,
      content: "+关注",
      bg_color: "#e0efed",
      ft_color: "#25b6a0",
      avatar:'',
      userInfo:{},
      pubTotal:null,
      articleList:[],
    };
  },
  mounted() {
    this.getUserInfor();
    this.getPublishList();
    this.getCheckStatus();
    this.getLikeCount();
    this.getPubCount();
    this.getFansCount();
  },
  methods: {
    favor() {
      if (this.liked===true) {
        this.cancelFocus();
        console.log('cancel',this.liked);
      } else {
        this.zenFocus();
      }
    },
    change() {
      this.bg_color = "#a3dad1";
      this.ft_color = "#e0efed";
    },
    goback() {
      if (this.liked) {
        this.bg_color = "#25b6a0";
        this.ft_color = "#e0efed";
      } else {
        this.bg_color = "#e0efed";
        this.ft_color = "#25b6a0";
      }
    },
    //跳转到医生展示
    toDoctorShow(doctorId) {
      let link = this.$router.resolve({
        path: "/doctorShow",
        query: {doctorId: doctorId},
      });
      window.open(link.href, "_blank");
    },
    async getLikeCount(){
      const res = await this.$api.reqLikeCount(this.$route.query.userId);
      if(res.code===200){
        this.like=res.counts;
      }
    },
    async getPubCount(){
      const res = await this.$api.reqPubCount(this.$route.query.userId);
      if(res.code===200){
        this.pub=res.counts;
      }
    },
    async getFansCount(){
      const res = await this.$api.reqFansCount(this.$route.query.userId);
      if(res.code===200){
        this.fans=res.total;
      }
    },
    async getUserInfor(){
      const res = await this.$api.reqUserDetail(this.$route.query.userId);
      if(res.code===200){
        this.avatar=this.$api.BASEURL+res.data.avatar;
        this.userInfo=res.data;
      }
    },
    async getPublishList(){
      const res = await this.$api.reqPublishList(this.$route.query.userId);
      if(res.code===200){
        for(let i=0; i<res.rows.length; i++){
          res.rows[i].publishTime=this.timeFommater(res.rows[i].publishTime);
        }
        this.pubTotal=res.total;
        this.articleList=res.rows;
      }
    },
    timeFommater(value) {
      var dateee = new Date(value).toJSON();
      var date = new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '');
      return date;
    },
    async getCheckStatus(){
      const that=this;
      that.liked = undefined;
      let obj={
        'subscriberId':that.$cookies.get('userId'),
        'subscribedId':that.$route.query.userId
      }
      const res = await that.$api.reqCheckStatus(obj);
      if(res.code===200){
        console.log('liked',res.msg);
        that.liked=res.msg;
        if (that.liked===true) {
          that.content = "已关注啦啦啦啦啦";
          that.bg_color = "#25b6a0";
          that.ft_color = "#e0efed";
        } else if(that.liked===false) {
          that.content = "+关注";
          that.bg_color = "#e0efed";
          that.ft_color = "#25b6a0";
        }
      }
    },
    async cancelFocus(){
      const res = await this.$api.reqDeleteFocus(this.$route.query.userId);
      if(res.code===200){
        this.liked=false;
        this.content = "+关注";
        this.bg_color = "#e0efed";
        this.ft_color = "#25b6a0";
      }
    },
    async zenFocus(){
      let obj={
        'subscribedId':this.$route.query.userId
      };
      const res = await this.$api.reqAddFocus(obj);
      if(res.code===200){
        this.liked=true;
        this.content = "已关注";
        this.bg_color = "#25b6a0";
        this.ft_color = "#e0efed";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.page {
  width: 100%;
  min-width: 1200px;
  text-align: left !important;
  min-height: calc(100vh - 65.5px);
  padding-top: 20px;
  box-sizing: border-box;
  background-color: #f6f7f9;
}

.user {
  width: 100%;
  height: 150px;
  background-color: #fff;
  display: flex;
  padding: 20px 20px;
  box-sizing: border-box;
  justify-content: space-between;

  .user_info {
    width: 500px;
  }

  .user_info_wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-left: 20px;

    span {
      text-align: left;
      font-size: 24px;
      color: #000;
      margin-bottom: 5px;
    }
  }
}

.user_notinfo_wrap {
  display: flex;
  //flex-direction: column;
  align-items: flex-start;
  margin-left: 20px;

  span {
    //text-align: left;
    font-size: 14px;
    color: #666;
    margin-bottom: 5px;
  }
}

.left_show_wrap {
  width: 110%;
  min-height: 100px;
  background-color: #fff;
  padding: 15px 30px;
  // padding-top:15px;
  box-sizing: border-box;

  span {
    text-align: left;
    font-size: 16px;
    color: #666;
    margin-bottom: 5px;

    &:first-child {
      font-size: 22px;
      color: #000;
      margin-bottom: 5px;
    }
  }

  .left_achi_wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-left: 20px;
  }
}

.intro {
  display: flex;
  //flex-direction: column;
  align-items: flex-start;
  margin-left: 20px;
  margin-bottom: 5px;

  span {
    //text-align: left;
    font-size: 14px;
    color: #666;
  }
}

.breadcrumb_wrap {
  width: 100%;
  height: 52px;
  background-color: #fff;
  display: flex;
  align-items: center;
  padding-left: 10px;
  box-sizing: border-box;
  font-size: 24px;
}

.page_card {
  background-color: #fff;
  margin-top: 20px;
  padding: 15px;
}

.el-row {
  margin-top: 20px;
}

.cjsc {
  color: #e05353;
}

.cjpl {
  color: #477cd6;
}

button {
  outline: none;
}

.guanzhu {
  top: 90px;
  margin-left: 400px;
}

.my_button {
  color: #25b6a0;
  background: #e0efed;
  border: #a3dad1 solid;
  width: 100px;
  border-radius: 20px;
  padding: 10px 20px;
  text-align: center;
  font-size: 18px;
  -webkit-transform: scale(0.7);
}
</style>
